home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / LZAPI.ZIP / SIMPLEC.ZIP / SIMPLE.C next >
Encoding:
C/C++ Source or Header  |  1995-04-19  |  3.0 KB  |  85 lines

  1. /* SIMPLE.C ----------------------------------------------------*
  2.  * Hello, this is a simple Example for the Usage of LZAPI
  3.  * in a C-Application
  4.  * It will simply copy all you INI-Files into an Archiv in the Temp
  5.  * Directory
  6.  * Bernd Herd 19.4.1995
  7.  *--------------------------------------------------------------*/
  8.  
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <alloc.h>
  13.  
  14. #include "lzapi.h"           // Needed for any Program that uses LZAPI
  15.  
  16. main()
  17. { LACTL    Ctl;               // LZAPI Control-Structure.
  18.   char     TempDirectory[130],       // File-Name for a File in the Temp Directory
  19.        WindowsDirectory[50];   // Directory-Name of the Windows-Directory with the INI-Files
  20.   LAERR    err;               // Errorcode Return-Variable from LZAPI-Function Call
  21.   OFSTRUCT dummy;
  22.  
  23.   // ------ Get Windows Directory --------------------------
  24.   GetWindowsDirectory( WindowsDirectory, sizeof(WindowsDirectory) );
  25.  
  26.   // ----- Get Temp-Directory ------------------------------
  27.   GetTempFileName(0, "LZH", 0, TempDirectory);
  28.   OpenFile( TempDirectory, &dummy, OF_DELETE);
  29.   strrchr(TempDirectory, '\\')[1] = 0;
  30.   strcat (TempDirectory, "INIS.LZH");
  31.  
  32.   // -------- Initialize Control Structure -----------------
  33.   memset(&Ctl, 0, sizeof(Ctl) );
  34.   Ctl.lStructSize = sizeof(Ctl);
  35.   Ctl.hwndOwner   = NULL;        // This Parameter is Recommended to hold
  36.                     // Your applications main Window
  37.  
  38.   // -------- Tell it, what to do --------------------------
  39.   Ctl.lpstrArchivFile = TempDirectory;   // For example C:\\TMP\INIS.LZH
  40.   Ctl.lpstrPath       = WindowsDirectory;// For example C:\\WINDOWS
  41.   Ctl.lpstrWildcards  = "*.INI";     // All INI-Files
  42.   Ctl.Flags          = LAF_SHORTNAMES;  // Recommended Option
  43.  
  44.  
  45.   // -------- Inform user what we are going to do ----------
  46.   printf("SIMPLE.C ---- Simple C-Code example for LZAPI\n"
  47.      "I'm going to Archive %Fs\\%Fs into Archiv %Fs\n",
  48.      Ctl.lpstrPath,
  49.      Ctl.lpstrWildcards,
  50.      Ctl.lpstrArchivFile);
  51.  
  52.   // -------- Perform Actions ------------------------------
  53.   err = LAAppend( &Ctl );
  54.   if (err != LAE_OK)
  55.        { LAErrMsg(err, &Ctl );
  56.          return 5;            // Cancel immediatly
  57.        }
  58.       else MessageBox( 0, "Hi, this was your Success for Today ;-)", "SIMPLE.C", MB_OK | MB_ICONINFORMATION);
  59.  
  60.  
  61.   printf("I'm going to list the Archiv %Fs\n", Ctl.lpstrArchivFile); 
  62.  
  63.   // -------- Let's show what we have done -----------------
  64.   Ctl.lpstrArchivFile = TempDirectory;     // Leave unchanged
  65.   Ctl.lpstrWildcards  = NULL;            // Show all Files
  66.   Ctl.lpstrListing    = (char *) malloc(30000); // Buffer for Listing
  67.  
  68.   err = LAList( &Ctl );
  69.   if (err != LAE_OK)
  70.        { LAErrMsg(err, &Ctl );
  71.          return 5;            // Cancel immediatly
  72.        }
  73.       else MessageBox( 0, "Listing buffer has Successfully been filled", "SIMPLE.C", MB_OK | MB_ICONINFORMATION);
  74.  
  75.   printf("Archiv Listing: \n"
  76.      "%Fs\n",
  77.      Ctl.lpstrListing);
  78.  
  79.   free(Ctl.lpstrListing);
  80.  
  81.   // --------- End Program ---------------------------------
  82.   return 0;
  83. }
  84.  
  85.